package com.yanqu.road.server.cmd.activity.chuhan.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ChuHanProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;


@Cmd(code = GameProtocol.S_CROSS_CHUHAN_POS_REWARD_SYNC, desc = "")
public class ChuHanCrossPosRewardSyncCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        ChuHanProto.CrossChuHanPositionSliverSyncMsg syncMsg = ChuHanProto.CrossChuHanPositionSliverSyncMsg.parseFrom(packet.getBytes());
        for(ChuHanProto.CrossChuHanPositionUserMsg userMsg : syncMsg.getUserList()){
            long userId = userMsg.getUserId();
            GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
            if(player != null){
                ChuHanProto.ChuHanPosRewardSyncMsg.Builder syncUserMsg = ChuHanProto.ChuHanPosRewardSyncMsg.newBuilder();
                syncUserMsg.addAllList(userMsg.getSliverUserList());
                player.sendPacket(Protocol.S_CHUHAN_POS_REWARD_SYNC % 20000, syncUserMsg);
            }
        }
    }

}
